package Gather.Advanced.TreeMap;

import java.util.Comparator;
import java.util.TreeMap;

public class Case {
    public static void main(String[] args) {

        //one();
        two();

    }
    public static void one(){
        /*
        键：整数表示Id
        值：字符串表示商品价格
        要求：按照Id的升序排列，按照Id的降序排序
         */
        TreeMap<Integer,String> tree=new TreeMap<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });

        tree.put(4,"康师傅");
        tree.put(1,"奥利奥");
        tree.put(2,"可口可乐");
        tree.put(3,"雪碧");

        System.out.println(tree);

    }


    public static void two(){
        /*
        键：学生对象
        值：籍贯
        要求：按照年龄进行升序排序
         */

        TreeMap<Studer,String>tree=new TreeMap<>();

       Studer stu1=new Studer("lisi",12);
        Studer stu2=new Studer("lifei",19);
        Studer stu3=new Studer("wangwu",24);
        Studer stu4=new Studer("zhangsan",45);

        tree.put(stu1,"上海");
        tree.put(stu2,"北京");
        tree.put(stu3,"长沙");
        tree.put(stu4,"广州");

        System.out.println(tree);

    }

}
